<div class="area-select">
    <h5>管辖区域</h5>
    <div class="area-box">
        <select name="province" id="provinceData">
            <option value="0">请选择</option>
        </select>
        <select name="city" id="cityData">
            <option value="0">请选择</option>
        </select>
        <select name="area" id="areaData">
            <option value="0">请选择</option>
        </select>
    </div>
    <div class="street-box">
        <select name="street" id="streetData">
            <option value="0">请选择</option>
        </select>
        <select name="committee" id="committeeData">
            <option value="0">请选择</option>
        </select>
    </div>
</div>
<script>
    var responseData = JSON.parse(sessionStorage.getItem("areainfo")), $province = $('#provinceData'), $city = $('#cityData'), $area = $('#areaData'), $street = $('#streetData'), $committee = $('#committeeData')
    //console.log(typeof responseData)
    $.each(responseData.data.regionList, function(index,val){
        if(val.levelType == 1){
            $("<option value="+val.id+" data-parentId="+val.parentId+">"+val.name+"</option>").appendTo($province)
        }
    })
    $province.on('change',function(){
        var id = $(this).val();
        $city.empty().append('<option value="0">请选择</option>')
        $area.empty().append('<option value="0">请选择</option>')
        $street.empty().append('<option value="0">请选择</option>')
        $committee.empty().append('<option value="0">请选择</option>')
        if(id != 0){
            sessionStorage.setItem("selectedCode", id)
        }else{
            sessionStorage.setItem("selectedCode", null)
        }
        if(id == 310000){
            $('.street-box').fadeIn()
        }else{
            $('.street-box').fadeOut()
        }
        $.each(responseData.data.regionList, function(index,val){
            if(val.parentId == id && val.levelType == 2) {
                $("<option value=" + val.id + " data-parentId=" + val.parentId + ">" + val.name + "</option>").appendTo($city)
            }
        })
    })
    $city.on('change',function(){
        var id = $(this).val();
        $area.empty().append('<option value="0">请选择</option>')
        $street.empty().append('<option value="0">请选择</option>')
        $committee.empty().append('<option value="0">请选择</option>')
        if(id != 0){
            sessionStorage.setItem("selectedCode", id)
        }else{
            sessionStorage.setItem("selectedCode", $province.find('option:selected').attr('value'))
        }
        $.each(responseData.data.regionList, function(index,val){
            if(val.parentId == id && val.levelType == 3) {
                $("<option value=" + val.id + " data-parentId=" + val.parentId + ">" + val.name + "</option>").appendTo($area)
            }
        })
    })
    $area.on('change',function(){
        var id = $(this).val();
        $street.empty().append('<option value="0">请选择</option>')
        $committee.empty().append('<option value="0">请选择</option>')
        if(id != 0){
            sessionStorage.setItem("selectedCode", id)
        }else{
            sessionStorage.setItem("selectedCode", $city.find('option:selected').attr('value'))
        }
        $.each(responseData.data.countyList, function(index,val){
            if(val.parentId == id && val.countrysideType == 0) {
                $("<option value=" + val.code + " data-parentId=" + val.parentId + ">" + val.name + "</option>").appendTo($street)
            }
        })
    })
    $street.on('change',function(){
        var id = $(this).val();
        $committee.empty().append('<option value="0">请选择</option>')
        if(id != 0){
            sessionStorage.setItem("selectedCode", id)
        }else{
            sessionStorage.setItem("selectedCode", $area.find('option:selected').attr('value'))
        }
        $.each(responseData.data.countyList, function(index,val){
            if(val.parentId == id && val.countrysideType != 0) {
                $("<option value=" + val.code + " data-parentId=" + val.parentId + ">" + val.name + "</option>").appendTo($committee)
            }
        })
    })
    $committee.on('change',function(){
        var id = $(this).val();
        if(id != 0){
            sessionStorage.setItem("selectedCode", id)
        }else{
            sessionStorage.setItem("selectedCode", $street.find('option:selected').attr('value'))
        }
    })
</script>